package edu.pmfbl.mnr.sem.mcmatm.gui;

import java.awt.*;
import java.awt.event.*;
//import java.util.*;
import javax.swing.*;

/**
 * <p>Title: MCMA Test Maker</p>
 *
 * <p>Description: </p>
 *
 * <p>Copyright: Copyright (c) 2009</p>
 *
 * <p>Company: KrndijaSoft</p>
 *
 * @author Ninoslav Krndija
 * @version 1.0
 */

public class MessageDialog extends JDialog
{
  JPanel contentPanel = new JPanel();
  JPanel buttonPanel = new JPanel();
  //private String password = null;
  /*ResourceBundle textRes = java.util.ResourceBundle.getBundle("com.borland.samples.dbswing.multilingual.gui.resources.TextRes",
                                                              LocaleChangeManager.getLocale());*/
  Component srcComp = null ;
  static int showCount = 0 ;
  GridLayout gridLayout1 = new GridLayout();
  BorderLayout borderLayout1 = new BorderLayout();
  JButton ukloniButton = new JButton();
  JLabel message = new JLabel();

  public MessageDialog()
  {
    super();
    try {
      jbInit();
    }
    catch (Exception e) {
      e.printStackTrace();
    }
    this.getContentPane().add(contentPanel);
//    pack();
  }

  public MessageDialog(Frame f)
  {
    super(f, "Poruka", true);
    try
    {
      jbInit();
    }
    catch(Exception e)
    {
      e.printStackTrace();
    }
    this.getContentPane().add(contentPanel);
  }
  public MessageDialog(Dialog d )
  {
    super(d, "Poruka", true);
    try
    {
      jbInit();
    }
    catch(Exception e)
    {
      e.printStackTrace();
    }
    this.getContentPane().add(contentPanel);
  }

  public void setSource(Component comp)
  {
    this.srcComp = comp ;
  }

  public void jbInit() throws Exception
  {
    contentPanel.setLayout(borderLayout1);
    buttonPanel.setLayout(gridLayout1);
    gridLayout1.setHgap(10);
    borderLayout1.setHgap(10);
    ukloniButton.setText("Ukloni");
    ukloniButton.addActionListener(new java.awt.event.ActionListener() {

      public void actionPerformed(ActionEvent e) {
        ukloniButton_actionPerformed(e);
      }
    });
    message.setText("");
    message.setHorizontalAlignment(SwingConstants.CENTER);
    contentPanel.add(buttonPanel, BorderLayout.SOUTH);
    buttonPanel.add(ukloniButton, null);
    contentPanel.add(message, BorderLayout.CENTER);

    this.setSize(new Dimension(300,100));
  }

  void ukloniButton_actionPerformed(ActionEvent e)
  {
    dispose();
    showCount-- ;
    if(srcComp != null)
      srcComp.requestFocus() ;
  }

  void this_windowClosing(WindowEvent e)
  {
    dispose();
    showCount-- ;
    if(srcComp != null)
      srcComp.requestFocus() ;
  }

  public void addNotify()
  {
    super.addNotify();
    this.pack();
    Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
    Dimension frameSize = this.getPreferredSize();
    if (frameSize.height > screenSize.height)
      frameSize.height = screenSize.height;
    if (frameSize.width > screenSize.width)
      frameSize.width = screenSize.width;
    this.setLocation((screenSize.width - frameSize.width) / 2, (screenSize.height - frameSize.height) / 2);
  }

  public String getMessage()
  {
    return message.getText();
  }

  public void setMessage(String m)
  {
    message.setText(m);
  }

  public void show()
  {
    /**@todo: Preklapanje java.awt.Dialog show metoda*/
    showCount++ ;
    super.show();
  }

  static public int getShowCount()
  {
    return showCount;
  }
}
